import React from 'react'
import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx'
import { withRouter } from 'react-router-dom'
import RadioList from './RadioList'
import ReturnButton from './ReturnButton'
import { RouteLayout } from 'weaver-mobile-page';
import { Bubble, Tools} from 'weaver-mobile'
import * as VariableKeys from "../../../constants/variableKey";
const ButtonGroup = RouteLayout.ButtonGroup;
const getLabel = Tools.getLabel;
@inject('wfRejectChooseStore','wfSignInputStore')
@withRouter
@observer
class RejectChoose extends React.Component {
    componentDidMount() {
        const { location = {}, wfRejectChooseStore } = this.props;
        const { chooseInfo } = location;
        const { resetToInit,doInit } = wfRejectChooseStore;
        resetToInit();
        doInit(chooseInfo);
    }

    handleOnClick = (e) => {
        const { wfRejectChooseStore, location, history } = this.props;
        const { callback } = location;
        const { allData, resetToInit } = wfRejectChooseStore;
        const { values, isHasSubmitMethod, rejectList} = allData;
        // 判断是否选择退回节点
        if (values.rejectNodeKey === "" && rejectList.data.length > 0) {
            Bubble.warning(getLabel(500331,'必须选择退回节点'), 2);
        } else if (values.isSubmitDirect === "" && isHasSubmitMethod) {
            Bubble.warning(getLabel(500332,'必须选择退回后再提交的处理方式'),2);
        } else {
            resetToInit();
            if (typeof callback === "function") {
                callback(toJS(values))
            }
            history.go(-1);
        }
    }
    render() {
        const { wfRejectChooseStore } = this.props;
        const { allData } = wfRejectChooseStore;
        const { datas } = allData;
        return (
            <div style={{ height: "100%" }}>
                <div className="wf_return" >
                    <RadioList titletype={0} datas={datas} />
                    <RadioList titletype={1} datas={datas} />
                    <RadioList titletype={2} datas={datas} />
                </div>
                <div style={{ position: "absolute", bottom: "0", height: "50px", width: "100%" }}>
                    <ButtonGroup
                        data={[
                            {
                                key: 'unset',
                                text: getLabel(201,"取消"),
                                onClick: () => {
                                    const { controlVariableMap } = this.props.wfSignInputStore;
                                    this.props.history.go(-1);
                                    controlVariableMap(VariableKeys.CURR_OPERATE_TYPE,{});
                                },
                                type: '',
                            },
                            {
                                key: 'save',
                                text: getLabel(826,"确定"),
                                onClick: this.handleOnClick,
                                type: 'primary',
                            },
                        ]}
                    />

                </div>
            </div>)
    }
}

export default RejectChoose;